<head>
   <script type="text/javascript">
						$(function() {
				$("table")
					.tablesorter({widthFixed: true}) 
					<!--.tablesorter({debug: true})-->
					.tablesorterPager({container: $("#pager1")});
			});
			
    </script>   
    
      <script>
			
		
		
			$(function() {
				var bayar = $( "#bayar" ),
					tanggal = $( "#tanggal" ),
					melalui = $( "#melalui" ),
					allFields = $( [] ).add( bayar ).add( tanggal ).add( melalui ),
					tips = $( ".validateTips" );
		 
				function updateTips( t ) {
					tips
						.text( t )
						.addClass( "ui-state-highlight" );
					setTimeout(function() {
						tips.removeClass( "ui-state-highlight", 1500 );
					}, 500 );
				}
		 
				/*function checkLength( o, n, min, max ) {
					if ( o.val().length > max || o.val().length < min ) {
						o.addClass( "ui-state-error" );
						updateTips( "Panjang dari " + $('#customer option:selected').text() + " hanya bisa dari" +
							min + " sampai " + max + " (sesuai jumlah hari)." );
						return false;
					} else {
						return true;
					}
				}*/
				/*
				function checkRegexp( o, regexp, n ) {
					if ( !( regexp.test( o.val() ) ) ) {
						o.addClass( "ui-state-error" );
						updateTips( n );
						return false;
					} else {
						return true;
					}
				}*/
		 
				$( "#dialog-formA" ).dialog({
					autoOpen: false,
					height: 400,
					width: 350,
					modal: true,
					buttons: {
						"Bayar": function() {
							var bValid = true;
							allFields.removeClass( "ui-state-error" );
							
							/*bValid = bValid && checkLength( name, "Hari", 1, 3 );
							bValid = bValid && checkLength( email, "Keterangan", 1, 3 );*/
						   
		 
							if ( bValid ) {
								
								var base_url = "<?php echo base_url(); ?>";
								
    							//var invoId  = invo[1]; 
								var delURL = $(this).data("invoValue").split("div_");
   								var delID  = delURL[1];  
								$.ajax({
									url: '<?php echo base_url(); ?>invoice/ajaxAddBayar/' +delID,
									type: 'POST',
									data:{"bayar": bayar.val(), "tanggal": tanggal.val(), "melalui": melalui.val(), "noInvo": delID, "total":$('#tagihan_'+delID).val(), "duedate":$('#due_'+delID).val()},
									success: function (result) {
										alert("Input Pembayaran Sukses");
									}
																			 
								}); 
								/*$('#tr_' + delID).remove();
								$("#paytermPlace").load("<?php echo base_url(); ?>invoice/ajaxLoadPayTerm");
								$("#background-image > tbody").append($.get());*/
								/*var loadurl2 = "{{=<?php echo base_url(); ?>invoice/ajaxLoadView", {noInvo:delID}}};
								$.get(loadurl2,function(data){
									$('background-image').append(data);   
								},'html');*/
								invoJenisBarang('#selectjenis', '#inputjenis', '#searchPlace', '0');
								$( this ).dialog( "close" );
								
							}
						},
						Batal: function() {
							$( this ).dialog( "close" );
						}
					},
					close: function() {
						allFields.val( "" ).removeClass( "ui-state-error" );
					}
				});
		 
				$( ".ajaxbayar" )
					
					.button()
					.live('click', function(){
						var nomor = $(this).attr("id");
						var spliting = nomor.split("div_");
   						var realVal  = spliting[1]; 
						var tagihan=$('#tagihan_'+realVal).val();
						var bayar=$('#bayar_'+realVal).val();
						var tanggal=$('#tanggal_'+realVal).val();
						var melalui=$('#method_'+realVal).val();
						var pt=$('#perusahaan_'+realVal).val();
						tagihanView = changeFormatRp(tagihan);
						$("#tagihan").val(tagihanView);
						$("#bayar").attr("placeholder",bayar);
						$("#tanggal").val(tanggal);
						$("#melalui").val(melalui);
						$("#headDialog1Bill").text(pt)
						$( "#dialog-formA" ).data("invoValue", $(this).attr("id")).dialog( "open" );
					});
			});
		</script>
            
</head>
 <div id="pager1" class="pager1">
        <table id="background-image"> 
            <thead> 
            	<?php if(empty($invoice)){
					?>
                    <tr>
                    	<td colspan="7" align="center">Tidak ada invoice</td>
                    </tr>
                    <?php
				}else{?>
                <tr> 
                	<th></th>
                    <th>No Invoice</th>
                    <th>Perusahaan</th>
                    <th>Nama</th> 
                    <th>Tgl Transfer</th>               
                    <th>Transfer</th>
                    <th>Status</th>
                    <th>Due</th>
                    <th>Action</th>
                </tr> 
            </thead> 
            <tbody> 
            	
           		<?php $i=0; foreach ($invoice as $invoice1){?>
					<tr id="tr_<?php echo $invoice1['invoice_no'];?>" >
                <!--onclick="javascript:invoDet(
                        '#invo_<?php echo $invoice1['invoice_id'];?>', '#placeResult', 
                        '<?php echo $invoice1['invoice_id'];?>', '0')"-->
                        <td><input type="checkbox" name="invoviewcheck[]" id="invoviewcheck[]"  value="<?php echo $invoice1['invoice_no']?>"/></td>
                        <td id="td_<?php echo $invoice1['invoice_no'];?>"><?php echo $invoice1['invoice_no'];?></td> 
                        <td><?php echo $invoice1['pt_name'];?></td>
                        <td><?php echo $invoice1['customer_name'];?></td>
                        <td><?php echo $invoice1['tglBayar'];?></td>  
                        <td><?php echo $invoice1['paymethod'];?></td> 
                        <input type="text" value="<?php echo $invoice1['total'];?>" id="tagihan_<?php echo  $invoice1['invoice_no'];?>" style="display:none" />
                        <input type="text" value="<?php echo $invoice1['paymethod'];?>" id="method_<?php echo  $invoice1['invoice_no'];?>" style="display:none" />
                        <input type="text" value="<?php echo $invoice1['tglBayar'];?>" id="tanggal_<?php echo  $invoice1['invoice_no'];?>" style="display:none" />
                        <input type="text" value="<?php echo $invoice1['pt_name'];?>" id="perusahaan_<?php echo  $invoice1['invoice_no'];?>" style="display:none" />
                        <input type="text" value="<?php echo $invoice1['duedate'];?>" id="due_<?php echo  $invoice1['invoice_no'];?>" style="display:none" />
                        <input type="text" value="<?php echo $invoice1['bayar'];?>" id="bayar_<?php echo  $invoice1['invoice_no'];?>" style="display:none" />
                      
                        <td><?php 
                            if	($invoice1['status']=="Belum Bayar"){
                                    ?><div id="div_<?php echo $invoice1['invoice_no'];?>" class="ajaxbayar" style="cursor:pointer"><font color="#FF0000">Belum Bayar</font></div>
                                <?php } else if($invoice1['status']=="Belum Lunas"){ ?>
                                    <div id="div_<?php echo $invoice1['invoice_no'];?>" class="ajaxbayar" style="cursor:pointer"><font color="#FF9900">Belum Lunas</font></div> <?php
                                }else{?>
									<div id="div_<?php echo $invoice1['invoice_no'];?>" class="ajaxbayar" style="cursor:pointer"><font color="#00CC33">Lunas</font></div>
								<?php }?>
                        </td>
                        <td><?php 
                            if	($invoice1['status']=="Lunas"){
                                    ?><font color="#00FF33">Lunas</font>
                                <?php } else{ ?>
                                	<?php if($invoice1['due']=="Terlambat"){?>
										<font color="#FF0000">Terlambat</font>
									<?php }else{ ?>
                                    	<font color="#00FF00">Belum Terlambat</font>
									<?php }?>
								<?php }?>
                        </td> 
                       
                        <td><a href="<?php echo site_url('invoice/edit/' . $invoice1['invoice_no'])?>">View & Edit</a></td>
                    </tr> 
                    
				<?php $i++;} ?>
           		
       		
           
            </tbody> 
           
            </table> 
    		<div class="title" align="right">
           
        		<input type="submit" name="btnGener" value="Generate Pdf" class="button_red" />
           	          
            </div>
                        <div class="success" id="sukses"><?php echo (isset($success))?$success:"";?>&nbsp;</div>

            </form>
            <form>
                <img src="<?php echo base_url();?>img/first.png" class="first" title="back to first"/>
                <img src="<?php echo base_url();?>img/prev.png" class="prev" title="previous"/>
                <input type="text" class="pagedisplay"/>
                <img src="<?php echo base_url();?>img/next.png" class="next" title="next"/>
                <img src="<?php echo base_url();?>img/last.png" class="last" title="go to last"/>
               
                <select class="pagesize">
                    <option selected="selected"  value="10">10</option>
                	<option value="15">15</option>
                    
                </select>
            
        	</form>
            
            </div>
            <?php }?>
    	</div>
       
    </div>      
    
</div>

  <?php /*================================================================*/
		// add payterm
		?>
         <div id="dialog-formA" title="Lakukan Pembayaran">
       	 Perusahaan: <div id="headDialog1Bill" class="headdiag"></div>
       
    	
 
            <form>
            <fieldset>
                <label for="tagihan">Tagihan</label>
                <input type="text" name="tagihan" id="tagihan" class="text ui-widget-content ui-corner-all" disabled="disabled" />
                <label for="bayar">Bayar</label>
                <input type="text" name="bayar" id="bayar" value="" class="text ui-widget-content ui-corner-all"/>
                <label for="tanggal">Tanggal Bayar(cnth: 08 Nov 2012)</label>
                <input type="text" name="tanggal" id="tanggal" class="text ui-widget-content ui-corner-all" />
                <label for="melalui">Bayar Melalui</label>
                <input type="text" name="melalui" id="melalui" value="" class="text ui-widget-content ui-corner-all" />
                
            </fieldset>
            </form>
        </div>
 
